package com.bjb.vr.manager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjb.vr.common.ao.ResDictionaryAo;
import com.bjb.vr.common.dto.ResDictionary;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.ResCascadeService;
import com.bjb.vr.common.service.ResDictionaryService;
import com.bjb.vr.common.vo.ResDictionaryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 字典列表
 *
 * @version 1.0.0
 * @author: HuJingBo
 * @time: 2022/3/24 13:40
 */
@RestController
@RequestMapping("/api/manager/v1")
public class DictionaryController {

    @Autowired
    ResDictionaryService dictionaryService;

    @Autowired
    ResCascadeService resCascadeService;
    /**
     * 查询字典
     *
     * @param resDictionaryAo
     * @return
     */
    @PostMapping("/queryDictionary")
    public BaseResult queryDictionary(@RequestBody ResDictionaryAo resDictionaryAo) {
        IPage<ResDictionaryVo> voIPage = dictionaryService.queryDictionary(resDictionaryAo);
        return CommonResult.Ok().setResult(voIPage);
    }

    /**
     * 查询字典--根据type
     *
     * @param resDictionaryAo
     * @return
     */
    @PostMapping("/queryDictionaryByType")
    public BaseResult queryDictionaryByType(@RequestBody ResDictionaryAo resDictionaryAo) {
        List<ResDictionaryVo> resDictionaryList = null;
        if(resDictionaryAo.getDictType().equals("01")) {
            resDictionaryList =  resCascadeService.queryDictionaryByPeriodLink(resDictionaryAo);
        }else if(resDictionaryAo.getDictType().equals("18")){
            resDictionaryList = resCascadeService.getResDictionaryDJList("2");
        }else{
            resDictionaryList = dictionaryService.queryDictionaryByPeriodLink(resDictionaryAo);
        }
        IPage<ResDictionaryVo> voIPage = new Page<ResDictionaryVo>(resDictionaryAo.getCurrent(), resDictionaryAo.getSize(), resDictionaryList.size());
        voIPage.setRecords(resDictionaryList);
        return CommonResult.Ok().setResult(voIPage);
    }

    /**
     * 查询字典--根据type--层级关系
     *
     * @param resDictionaryAo
     * @return
     */
    @PostMapping("/queryDictListByType")
    public BaseResult queryDictListByType(@RequestBody ResDictionaryAo resDictionaryAo) {
        List<ResDictionaryVo> resDictionaryList = dictionaryService.queryDictListByType(resDictionaryAo);
        return CommonResult.Ok().setResult(resDictionaryList);
    }

    /**
     * 查询字典--根据code--层级关系
     *
     * @param resDictionaryAo
     * @return
     */
    @PostMapping("/queryDictListByCode")
    public BaseResult queryDictListByCode(@RequestBody ResDictionaryAo resDictionaryAo) {
        List<ResDictionaryVo> resDictionaryList = dictionaryService.queryDictListByCode(resDictionaryAo);
        return CommonResult.Ok().setResult(resDictionaryList);
    }
}
